<template>
	<view>
		<cu-custom :bgLinerBorder="true" :isBlack="false" >
			<block slot="content">发票上传</block>
		</cu-custom>
		<view class="contents">
			<view class="text-center m-b-10">
				上传发票可获取抵扣券
			</view>
			<view class="flex flex-wrap">
				<view class="upload_icon position-rel" v-for="(item,index) in list" :key="index" @click="preImg(list,index)">
					<image class="add-s" :src="item"></image>
					<image src="/static/img/trash.png" class="trash" @click.stop="del(index)"></image>
				</view>
				<view class="upload_icon flex align-center justify-center" @click="upImg" v-if="list.length<1">
					<image class="add-s-s" src="/static/img/add-s.png"></image>
				</view>
			</view>
			<view class="flex justify-center" @click="toUser">
				<view class="tip-btn">
					快来云顶餐厅点餐吧
				</view>
			</view>
		</view>
		<view style="height: 130rpx;"></view>
		<view class="bottom-wrap flex justify-space-around">
			<view class="bottom-btn bottom-btn2" @click="sub()">
				保存
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[],
				id:0
			}
		},
		onLoad(option) {
			if(option.id){
				this.id = option.id;
			}
			let id = this.getUrlId();
			if(id){
				this.id = id;
			}
			if(this.id&&this.$store.state.shareId==null){
				this.$store.state.shareId = this.id;
			}else{
				this.$store.state.shareId=null;
			}
			this.getMine();
		},
		methods: {
			getUrlId() {
				console.log(111)
				var url = new URL(window.location.href);
				var searchParams = url.searchParams;
				
				console.log('id=',searchParams.get('id'))
				return searchParams.get('id');
			},
			getMine(){
				let data = {
					
				}
				this.$http('/apicloud/User/userInfo',data).then(res=>{
					if(res.code == 200){
						
					}
				})
			},
			preImg(urls,current){
				uni.previewImage({
					urls,
					current
				})
			},
			del(index){
				this.list.splice(index,1);
			},
			upImg(){
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					// sourceType: ['album'], //从相册选择
					success: (res) => {
						uni.showLoading({
							title:'上传中...'
						})
						console.log(res)
						let file = res.tempFiles[0];
						this.$util.uploadService(file,(e)=>{
							console.log(e)
							this.list.push(e);
							uni.hideLoading();
						})
					}
				})
			},
			sub(){
				let data = {
					channel_id:this.id,
					invoice_url:this.list.join(',')
				};
				this.$http('/apicloud/User/userUploadInvoice',data).then(res=>{
					if(res.code == 200){
						this.$util.showToast(res.mess);
						setTimeout(()=>{
							this.list = [];
						},1500)
					}else{
						this.$util.showToast(res.mess);
					}
				})
			},
			toUser(){
				let url = this.$url + '/userh5'
				window.location.href = url;
			},
		}
	}
</script>

<style lang="less">
	.sel{
		width: 44rpx;
		height: 44rpx;
	}
	.upload_icon{
		margin-bottom: 20rpx;
		background: #f4f4f4;
		width: 690rpx;
		height: 500rpx;
	}
	.add-s{
		width: 690rpx;
		height: 500rpx;
	}
	.add-s-s{
		width: 230rpx;
		height: 200rpx;
	}
	.bottom-wrap {
		box-shadow: 0px -3px 6px rgba(0, 0, 0, 0.07);
		border-radius: 20px 20px 0 0;
		height: 130rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 100;
		background: #ffffff;
		width: 100%;
		padding: 15rpx 30rpx 0 30rpx;
	
		.bottom-btn {
			width: 100%;
			height: 76rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #ffffff;
			font-weight: bold;
			border-radius: 60rpx;
		}
	
	
		.bottom-btn2 {
			background: #FF5200;
		}
	}
	.trash{
		width: 36rpx;
		height: 36rpx;
		position: absolute;
		right: 0;
		top: 0;
		z-index: 5;
	}
	.tip-btn{
		background: #FF5200;
		color: #fff;
		width: 55%;
		height: 70rpx;
		text-align: center;
		line-height: 70rpx;
		border-radius: 10rpx;
	}
</style>
